import { createApp, createVNode, render } from 'vue'
import App from './App.vue'
import router from './route'
import ElementUi from 'element-plus'
import 'element-plus/dist/index.css'
import loadingBar from './components/loadingBar.vue'

//虚拟dom挂载
const Vnode = createVNode(loadingBar)
render(Vnode, document.body)


const app = createApp(App)
app.use(router)
app.use(ElementUi)
app.mount('#app')

//设置白名单
const whileList = ['/']
router.beforeEach((to, from, next) => {
    Vnode.component?.exposed?.startLoading()
    if(whileList.includes(to.path) || localStorage.getItem('token')) {
        next()
    } else {
        next('/')
    }
})

router.afterEach((to, from)=> {
    Vnode.component?.exposed?.endLoading()
})